var oAddHot = document.getElementById('addHot');
var aInput = oAddHot.getElementsByTagName('input');
var oChoseAll = document.getElementById('choseAll');
var oHotGoods = document.getElementById('goodsID');
var sortWay;
var hotGoods = [];
if(aInput[0].checked)
{
	sortWay = 0;
}
else if(aInput[1].checked)
{
	sortWay = 1;
}
$(document).ready(function(){
	$.ajax({
		type:"post",
		url:"",
		async:true,
		data:'hotGoods',
		success:function(){
			
		},
		error:function(){
			$('#cue').html('跳转出现错误' + jqXHR.status);
		}
	});
	
	$.ajax({
		type:"get",
		url:"",
		async:true,
		dataTpye:'json',
		success:function(result){
			var data = JSON.parse(result);
			var html = '';
			$.each(data, function(commentIndex, comment){
								
	                 html += '<li><span class="goodsID">' + comment['goodsIntroduce'] 
	                 + '</span><input type="checkbox"/>'
	                 + '</li>';
            });
        	$('#goodsID').html(html);
		},
		error:function(){
			$('#cue').html('获取数据出现错误' + jqXHR.status);
		}
	});
});

//alert(aInput[0].checked);
if(sortWay)
{//alert(111);
		var aChecked = oHotGoods.getElementsByTagName('input');
		var aId = oHotGoods.getElementsByTagName('span');
		for(var i = 0;i < aId.length;i++ )
		{
			if(aChecked[i].checked)
			{
				hotGoods.push(aId[i].innerHTML);
			}
			
		}
		console.log(hotGoods);
}
var oReset = document.getElementById('reset');
oReset.onclick = function(){
	for(var j = 0; j < aChecked.length;j++)
	{
		aChecked[j].checked = false;
	}
}

function submitbtn_click(){
	var aLi = oHotGoods.getElementsByTagName('li');
	var hotGoodsArray = [];
	for(var i = 0; i < aLi.length;i++)
	{
		if($('#goodsID li:eq(i) input').checked)
		{
			hotGoodsArray.push($('#goodsID li:eq(i) span').html());
		}
	}
	
	
	$.ajax({
		type:"post",
		url:"",
		async:true,
		dataType:'Number',
		data:sortWay,
		success:function(){
			$('#cue').html('排序方式传送成功');
		},
		error:function(jqXHR){
			$('#cue').html('发送出现错误' + jqXHR.status);
		}
	});
	$.ajax({
		type:"post",
		url:"",
		async:true,
		dataType:'json',
		data:hotGoodsArray,
		success:function(){
			$('#cue').html('排序方式传送成功');
		},
		error:function(jqXHR){
			$('#cue').html('发送出现错误' + jqXHR.status);
		}
	});
}
